﻿DECLARE @HIS_AppointDate DATE
DECLARE @HIS_SourceNumber INT
DECLARE @HIS_TransFlow VARCHAR(100)
DECLARE @HIS_TransactionTime DATETIME
DECLARE @HIS_TimeinterVal VARCHAR(100)
DECLARE @HIS_PatientId VARCHAR(100)
DECLARE @HIS_PatientName VARCHAR(100)
DECLARE @HIS_sex VARCHAR(100)
DECLARE @HIS_DeptName VARCHAR(100)
DECLARE @HIS_DoctName VARCHAR(100)
DECLARE @HIS_Duty VARCHAR(100)
DECLARE @HIS_CheckGroupCode VARCHAR(100)

DECLARE @Var_RegisterId INT

SET @Var_RegisterId = @RegistId_In

SELECT @HIS_PatientId = PatientId 
FROM dbo.AP_PreRegist_DongRuan(NOLOCK) WHERE Id = @Var_RegisterId

SELECT  @HIS_AppointDate = a.ReservationDate 
       ,@HIS_SourceNumber = a.Id
       ,@HIS_TransFlow = a.TransNo
       ,@HIS_TransactionTime = a.OperDate
       ,@HIS_TimeinterVal = TID
       ,@HIS_PatientId = a.PatientId
       ,@HIS_PatientName = b.PatientName
       ,@HIS_sex = b.Sex
       ,@HIS_DeptName = a.DeptName
       ,@HIS_DoctName = a.DoctName
       ,@HIS_Duty = a.Spec    
       ,@HIS_CheckGroupCode = a.ClinicCode
FROM dbo.AP_ReservationSheet a(NOLOCK) 
LEFT JOIN dbo.PatientBase b(NOLOCK) ON b.PatientID = a.PatientId 
WHERE a.PatientId = @HIS_PatientId


SELECT CHECKNAME
      ,CHECKPRICE
      ,@HIS_AppointDate AS appointDate
      ,@HIS_SourceNumber AS sourceNumber
      ,@HIS_TransFlow AS transFlow
      ,@HIS_TransactionTime AS transactionTime
      ,NULL AS currentNumber
      ,@HIS_TimeinterVal AS clinicRange
      ,@HIS_PatientId AS patientId
      ,@HIS_PatientName AS [name]
      ,@HIS_sex AS sex
      ,@HIS_DeptName AS deptName
      ,@HIS_DoctName AS doctorName
      ,@HIS_Duty AS duty
FROM CHECKGROUPSHEET (NOLOCK) WHERE GROUPCODE = @HIS_CheckGroupCode
